class Solution {
public:
    int sumOddLengthSubarrays(vector<int>& arr) {
        int sum = 0;
        int n = arr.size();
        for (int S = 0; S < n; S++) {
            for (int L = 1; S + L <= n; L += 2) {
                int end = S + L - 1;
                for (int i = S; i <= end; i++) {
                    sum += arr[i];
                }
            }
        }
        return sum;
    }
};